package com.lsk.admin.interceptor;


import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.lsk.util.Syslog;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2018/3/14.
 */
public class SessionInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation invocation) {
        HttpSession session= invocation.getController().getSession();
        String url=invocation.getController().getRequest().getRequestURI();
        if (url.contains("/adminLogin") || url.equals("/") || url.contains("/adminIndex")){//不需要验证session
            invocation.invoke();
        }else {
            Object userId=session.getAttribute("userId");
            if (userId==null){
                invocation.getController().redirect("/");
                Syslog.info("session过期了，跳转至登录页面");
            }else {
                invocation.invoke();
            }
        }
    }
}
